class Setting < ActiveRecord::Base
  validates_uniqueness_of :name
  
  class << self
    def clear_cache
      @setting_list = nil
    end
    
    def setting_cache
      @setting_list ||= Setting.find(:all).inject({}) {|hash, setting| hash[setting.name.to_sym] = setting.value; hash}
    end
    
    def list
     setting_cache
    end
    
    def get(method)
      setting_cache[method.to_sym]
    end
    
    def method_missing(method_id, *arguments)
      if setting = get(method_id)
        setting
      else
        super
      end
    end
  end
  
end
